package main

import (
	"fmt"
	"time"
)

func main() {
	var intChan chan int = make(chan int, 100)
	exitChan := make(chan bool, 1)
	go writeData(intChan)
	go readData(intChan, exitChan)

	for {
		_, ok := <-exitChan
		if !ok {
			break
		}
	}
}

func writeData(intChan chan int) {
	for i := 1; i <= 5; i++ {
		intChan <- i
		fmt.Println("write ", i)
		time.Sleep(time.Second)
	}
	close(intChan)
}

func readData(intChan chan int, exitChan chan bool) {
	for {
		v, ok := <-intChan
		if !ok {
			break
		}
		fmt.Printf("read %d \n", v)
	}
	exitChan <- true
	close(exitChan)
}

func isEven(n int) bool {
	if n%2 == 0 {
		return true
	}
	return false
}
